#define _XOPEN_SOURCE  1
#define _SVID_SOURCE  1
#define _POSIX_SOURCE  1
#define _BSD_SOURCE  1
#include <header.h>
#include <shadow.h>
#include <errno.h>
#include <openssl/md5.h>


void computemd5(int file_descriptor, unsigned char *result) {
    MD5_CTX md5_ctx;
    unsigned char buffer[1024];
    ssize_t bytes_read;

    MD5_Init(&md5_ctx);
    while ((bytes_read = read(file_descriptor, buffer, sizeof(buffer))) > 0) {
        MD5_Update(&md5_ctx, buffer, bytes_read);
    }
    MD5_Final(result, &md5_ctx);
}

void printmd5(unsigned char *md) {
    for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
        printf("%02x", md[i]);
    }
    printf("\n");
}

// 将 unsigned char 数组转换为 char 字符串
void ucharToHexString(unsigned char *input, char *output, int length) {
    for (int i = 0; i < length; ++i) {
        sprintf(output + (i * 2), "%02x", input[i]);
    }
    output[length * 2] = '\0'; // 添加字符串结束符
}

int main(int argc, char *argv[]) {
    char str1[] = "/";
    char str2[] = "chizuru";
    char result[100];

    // 使用 snprintf() 将两个字符串合并到 result 数组中
    snprintf(result, sizeof(result), "%s%s", str1, str2);
    printf("res:%s\n", result);
    return 0;
}



